//
//  CVCellOfInsideSpecialistCharts.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/20.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "CVCellOfInsideSpecialistCharts.h"
#import "BaseTableView.h"
#import "MJMacro.h"
#import "TVCellOfInsideSpecialistCharts.h"
#import "ZWYNetTool.h"
#import "BaseOfUserDataInsideSpecialistCharts.h"
#import "CounterOfUserDataInsideSpecialistCharts.h"
#import "DataOfInsideSpecialistCharts.h"
#import "ProfileOfUserDataInsideSpecialistCharts.h"
#import "RootClassOfInsideSpecialistCharts.h"
#import "UserOfDataInsideSpecialistCharts.h"
#import "Way_Type_SetOfDataInsideSpecialistCharts.h"
#import "UIImageView+WebCache.h"
@interface CVCellOfInsideSpecialistCharts()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) RootClassOfInsideSpecialistCharts *rootClassOfInsideSpecialistCharts;
@property (nonatomic, strong) BaseTableView *tableViewOfInsideSpecialistCharts;
@end
@implementation CVCellOfInsideSpecialistCharts
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 创建tabelView
        [self createTabelView];
    }
    return self;
}
#pragma mark set 
- (void)setNumberOfItem:(NSInteger)numberOfItem{
    _numberOfItem = numberOfItem;
    // 处理数据
    [self handleData];
}
#pragma mark - 数据处理
- (void)handleData{
    switch (_numberOfItem) {
        case 0:
        {
            [ZWYNetTool GET:@"http://yiapi.xinli001.com/v2/yi/teacher-list.json?key=18ee0593a01c07f71d28fa936d671457&_platform=ios&_version=4.0&sort=ho" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
                _rootClassOfInsideSpecialistCharts = [RootClassOfInsideSpecialistCharts modelDic:result];
                [self.tableViewOfInsideSpecialistCharts reloadData];
            } andFailureBlock:^(NSError *error) {
                
            }];
        }
            break;
        case 1:
        {
            [ZWYNetTool GET:@"http://yiapi.xinli001.com/v2/yi/teacher-list.json?key=18ee0593a01c07f71d28fa936d671457&_platform=ios&_version=4.0&sort=rate" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
                _rootClassOfInsideSpecialistCharts = [RootClassOfInsideSpecialistCharts modelDic:result];
                [self.tableViewOfInsideSpecialistCharts reloadData];
            } andFailureBlock:^(NSError *error) {
                
            }];
        }
            break;
        case 2:
        {
            [ZWYNetTool GET:@"http://yiapi.xinli001.com/v2/yi/teacher-list.json?key=18ee0593a01c07f71d28fa936d671457&_platform=ios&_version=4.0&sort=yuyue" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
                _rootClassOfInsideSpecialistCharts = [RootClassOfInsideSpecialistCharts modelDic:result];
                [self.tableViewOfInsideSpecialistCharts reloadData];
            } andFailureBlock:^(NSError *error) {
                
            }];
        }
            break;
        default:
        {
            [ZWYNetTool GET:@"http://yiapi.xinli001.com/v2/yi/teacher-list.json?key=18ee0593a01c07f71d28fa936d671457&_platform=ios&_version=4.0&sort=new" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
                _rootClassOfInsideSpecialistCharts = [RootClassOfInsideSpecialistCharts modelDic:result];
                [self.tableViewOfInsideSpecialistCharts reloadData];
            } andFailureBlock:^(NSError *error) {
                
            }];
        }
            break;
    }
    
}
#pragma mark - 创建tableView
- (void)createTabelView{
    self.tableViewOfInsideSpecialistCharts = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT  - 44) style:UITableViewStylePlain];
    [self.contentView addSubview:self.tableViewOfInsideSpecialistCharts];
    self.tableViewOfInsideSpecialistCharts.delegate = self;
    self.tableViewOfInsideSpecialistCharts.dataSource = self;
    [self.tableViewOfInsideSpecialistCharts registerNib:[UINib nibWithNibName:@"TVCellOfInsideSpecialistCharts" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TVCellOfInsideSpecialistCharts"];
}
#pragma mark - tableView 代理方法 row 的数量的确定
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _rootClassOfInsideSpecialistCharts.data.count;
}
#pragma mark - tableView 的row的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return SCREEN_HEIGHT * 0.65;
}
#pragma mark - tableView 代理方法 cell 的赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TVCellOfInsideSpecialistCharts *cell = [tableView dequeueReusableCellWithIdentifier:@"TVCellOfInsideSpecialistCharts" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    cell.myBackgroundView.layer.cornerRadius = 20;
    cell.myBackgroundView.clipsToBounds = 20;
    [cell.coverImageView sd_setImageWithURL:[NSURL URLWithString:_rootClassOfInsideSpecialistCharts.data[indexPath.row].cover] placeholderImage:[UIImage imageNamed:@"0"]];
    [cell.avatarImageView sd_setImageWithURL:[NSURL URLWithString:_rootClassOfInsideSpecialistCharts.data[indexPath.row].user.avatar] placeholderImage:[UIImage imageNamed:@"0"]];
    cell.avatarImageView.layer.cornerRadius = 30;
    cell.avatarImageView.clipsToBounds = YES;
    cell.nicknameLabel.text = _rootClassOfInsideSpecialistCharts.data[indexPath.row].user.nickname;
    cell.honorLabel.text = _rootClassOfInsideSpecialistCharts.data[indexPath.row].honor;
    cell.briefLabel.text = _rootClassOfInsideSpecialistCharts.data[indexPath.row].brief;
    cell.cityLabel.text = _rootClassOfInsideSpecialistCharts.data[indexPath.row].city;
    return cell;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
